package com.ljq.anonymousInnerClassAndAPIs;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import java.util.Random;

/**
 * Description: 常用api2
 * Author: A
 * Date: 2025/2/24
 * Time: 16:30
 */
public class APIs2 {
    public static void main(String[] args) {
        bigDecimal();
    }
    public static void bigIntegerEx() {
        // 大数额运算
        int num = 10;
        BigInteger z = BigInteger.ONE; // 初始化为1
        for (int i = 2; i < num; i++) {
//            valueOf将long类型数据装换成Integer
            z  =   z.multiply(BigInteger.valueOf(i));

        }
        System.out.println(num + "! = " +z );
        BigInteger prime = BigInteger.probablePrime(3, new Random());
        System.out.println(prime);
    }

    public static void bigDecimal(){
        BigDecimal price = new BigDecimal("19.99"); // 商品价格
        BigDecimal quantity = new BigDecimal("3"); // 购买数量
        BigDecimal discount = new BigDecimal("0.10"); // 10% 折扣

        // 计算总价
        BigDecimal totalPrice = price.multiply(quantity);
        System.out.println("总价: " + totalPrice);

        BigDecimal discountAmount = totalPrice.multiply(discount);
        BigDecimal finalPrice = totalPrice.subtract(discountAmount);
        System.out.println("折扣后的价格: " + finalPrice.setScale(2, RoundingMode.HALF_UP)); // 保留两位小
    }
}
